﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Xts
{
    namespace XInterBank
    {
        namespace AuthorityClient
        {
            public class XSessionAgent_sync
            {
                protected Ice.Communicator x_ic;
                protected Ice.Logger x_logger;
                protected IXSessionPrx x_sessionPrx;

                public bool IsValid { get { return x_sessionPrx != null; } }

                public XSessionAgent_sync(ref Ice.Communicator ic, ref Ice.Logger logger)
                {
                    x_ic = ic;
                    x_logger = logger;
                    x_sessionPrx = null;
                }

                public bool Initialize(string sessionDsb)
                {
                    try
                    {
                        Ice.ObjectPrx objPrx = x_ic.stringToProxy(sessionDsb);
                        x_sessionPrx = IXSessionPrxHelper.checkedCast(objPrx);
                        return true;
                    }
                    catch (Ice.Exception ex)
                    {
                        x_logger.error(ex.Message);
                    }
                    return false;
                }

                public XRetrieveOrderDeliveryRsp RetrieveOrderDelivery()
                {
                    if (!IsValid)
                    {
                        x_logger.error("The XSessionAgent_sync object is NOT valid.");
                        return null;
                    }

                    try
                    {
                        return x_sessionPrx.RetrieveOrderDelivery();
                    }
                    catch (Ice.Exception ex)
                    {
                        x_logger.error(ex.Message);
                    }

                    return null;
                }

                public XRetrieveTradingQueryRsp RetrieveTradingQuery()
                {
                    if (!IsValid)
                    {
                        x_logger.error("The XSessionAgent_sync object is NOT valid.");
                        return null;
                    }

                    try
                    {
                        return x_sessionPrx.RetrieveTradingQuery();
                    }
                    catch (Ice.Exception ex)
                    {
                        x_logger.error(ex.Message);
                    }

                    return null;
                }
                public XOprtInfo SubscribeSnapshotData(string[] symbolIdList, string snapshotDataMonitorDsb)
                {
                    if (!IsValid)
                    {
                        x_logger.error("The XSessionAgent_sync object is NOT valid.");
                        return null;
                    }

                    try
                    {
                        return x_sessionPrx.SubscribeSnapshotData(symbolIdList, snapshotDataMonitorDsb);
                    }
                    catch (Ice.Exception ex)
                    {
                        x_logger.error(ex.Message);
                    }

                    return null;
                }
                public XOprtInfo SubscribeQuoteDetailData(string[] symbolIdList, string quoteDetailDataMonitorDsb)
                {
                    if (!IsValid)
                    {
                        x_logger.error("The XSessionAgent_sync object is NOT valid.");
                        return null;
                    }

                    try
                    {
                        return x_sessionPrx.SubscribeQuoteDetailData(symbolIdList, quoteDetailDataMonitorDsb);
                    }
                    catch (Ice.Exception ex)
                    {
                        x_logger.error(ex.Message);
                    }

                    return null;
                }
                public XOprtInfo SubscribeOrderNotify(string orderNotifyerDsb)
                {
                    if (!IsValid)
                    {
                        x_logger.error("The XSessionAgent_sync object is NOT valid.");
                        return null;
                    }

                    try
                    {
                        return x_sessionPrx.SubscribeOrderNotify(orderNotifyerDsb);
                    }
                    catch (Ice.Exception ex)
                    {
                        x_logger.error(ex.Message);
                    }

                    return null;
                }
            }
        }
    }
    
}
